<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="登录名" prop="userName">
        <el-input v-model="queryParams.userName" placeholder="请输入用户登录名" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" placeholder="性别" clearable style="width: 240px">
          <el-option v-for="dict in dict.type.sys_user_sex" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="员工编号" prop="employeeId">
        <el-input v-model="queryParams.employeeId" placeholder="请输入员工编号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="职级" prop="rankId">
        <el-select v-model="queryParams.rankId" placeholder="请选择岗位">
          <el-option v-for="item in postOptions" :key="item.postId" :label="item.postName"
            :value="item.postId"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="入职时间">
        <el-date-picker v-model="dateRange" style="width: 240px" value-format="yyyy-MM-dd" type="daterange"
          range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['system:person:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['system:person:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['system:person:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['system:person:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="personList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <!-- <el-table-column label="人员编号" align="center" prop="personId" /> -->
      <el-table-column label="姓名" align="center" prop="name" />
      <!-- <el-table-column label="用户登录名" align="center" prop="userName" /> -->
      <el-table-column label="头像" align="center" prop="headPhoto" />
      <el-table-column label="员工编号" align="center" prop="employeeId" />
      <el-table-column label="职级" align="center" prop="post.postName" />
      <!-- <el-table-column label="身份证号" align="center" prop="identityCard" />
      <el-table-column label="曾用名" align="center" prop="formerName" /> -->
      <el-table-column label="性别" align="center">
        <template slot-scope="scope">
          {{ scope.row.sex === '0' ? '男' : '女' }}
        </template>
      </el-table-column>
      <!-- <el-table-column label="出生年月日" align="center" prop="birthDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.birthDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="籍贯" align="center" prop="nativePlace" />
      <el-table-column label="政治面貌" align="center" prop="politicsStatus" />
      <el-table-column label="健康状况" align="center" prop="healthStatus" />
      <el-table-column label="血型" align="center" prop="bloodType" />
      <el-table-column label="入党年月日" align="center" prop="joinPartyDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.joinPartyDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="婚姻状况" align="center" prop="marriageStatus" />
      <el-table-column label="结(离)婚日期" align="center" prop="marDirDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.marDirDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现工作单位" align="center" prop="currentEmployer" />
      <el-table-column label="原工作单位" align="center" prop="originalEmployer" />
      <el-table-column label="离职原因" align="center" prop="leaveReason" /> -->
      <!-- <el-table-column label="参加工作年月日" align="center" prop="employmentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.employmentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="入职日期" align="center" prop="enterWorkDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterWorkDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="进入三周年月日" align="center" prop="enterThreeworks" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enterThreeworks, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="岗位性质" align="center" prop="jobNature" />
      <el-table-column label="人员类型" align="center" prop="personType" />
      <el-table-column label="劳动关系" align="center" prop="laborRelation" />
      <el-table-column label="专业技术职务" align="center" prop="professionTitle" />
      <el-table-column label="专业技术职务" align="center" prop="profTitleTenure" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.profTitleTenure, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="现工作岗位" align="center" prop="currentPosition" />
      <el-table-column label="现任职时间" align="center" prop="currentTenure" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.currentTenure, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="家庭住址" align="center" prop="homeAddress" />
      <el-table-column label="邮政编码" align="center" prop="postalCode" />
      <el-table-column label="家庭电话" align="center" prop="homeTelephone" />
      <el-table-column label="办公电话" align="center" prop="officeTelephone" />
      <el-table-column label="移动电话" align="center" prop="mobilePhone" />
      <el-table-column label="电子邮件" align="center" prop="email" />
      <el-table-column label="户口性质" align="center" prop="householdNature" />
      <el-table-column label="户口所在地" align="center" prop="householdRegistration" />
      <el-table-column label="出生地" align="center" prop="birthPlace" />
      <el-table-column label="兴趣爱好" align="center" prop="hobby" />
      <el-table-column label="懂何种外语" align="center" prop="knowForeign" />
      <el-table-column label="外语证书名称" align="center" prop="foreignCertificate" />
      <el-table-column label="熟练程度" align="center" prop="proficiency" />
      <el-table-column label="证书编码" align="center" prop="certificateCode" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['system:person:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-query" @click="handleView(scope.row)"
            v-hasPermi="['system:person:query']">详细</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
            v-hasPermi="['system:person:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改或查看人员基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1030px" :append-to-body="false"
      style="overflow-y: auto; height: 630px;">
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-row>
          <el-col :span="9">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" maxlength="50" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <el-form-item label="登录名" prop="userName">
              <el-input v-model="form.userName" maxlength="30" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="上传头像" prop="headPhoto">
              <el-input v-model="form.headPhoto" maxlength="100" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <userAvatar />
          <el-col :span="4">
            <el-form-item label="上传头像" prop="headPhoto">
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <div class="image-display" style="width: 100%; height: auto;">
              <personAvatar />
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="员工编号" prop="employeeId">
              <el-input v-model="form.employeeId" maxlength="50" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="职级">
              <el-input v-if="isQueryMode && form.post != null" v-model="form.post.postName" :readonly="isReadOnly" />
              <el-input v-else-if="isQueryMode && form.post == null" v-model="form.post" :readonly="isReadOnly" />
              <el-select v-else v-model="form.rankId" placeholder="请选择岗位" :readonly="isReadOnly">
                <el-option v-for="item in postOptions" :key="item.postId" :label="item.postName"
                  :value="item.postId"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="身份证号" prop="identityCard">
              <el-input v-model="form.identityCard" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="曾用名" prop="formerName">
              <el-input v-model="form.formerName" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别">
              <el-radio-group v-model="form.sex">
                <el-radio label="0">男</el-radio>
                <el-radio label="1">女</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="出生年月日" prop="birthDate">
              <el-date-picker clearable v-model="form.birthDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择出生年月日" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="民族" prop="nation">
              <!-- 查看模式时显示 -->
              <el-input v-if="isQueryMode" v-model="form.nation" :readonly="isReadOnly" />
              <!-- 编辑模式时显示下拉框 -->
              <el-select v-else v-model="form.nation" placeholder="请选择民族">
                <el-option v-for="nation in nations" :key="nation" :label="nation" :value="nation">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="籍贯" prop="nativePlace">
              <el-input v-model="form.nativePlace" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="政治面貌" prop="politicsStatus">
              <!-- 查看模式时显示 -->
              <el-input v-if="isQueryMode" v-model="form.politicsStatus" :readonly="isReadOnly" />
              <!-- 编辑模式时显示下拉框 -->
              <el-select v-else v-model="form.politicsStatus" placeholder="请选择政治面貌">
                <el-option v-for="politicsStatus in politicsStatuses" :key="politicsStatus" :label="politicsStatus"
                  :value="politicsStatus">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="健康状况" prop="healthStatus">
              <el-input v-model="form.healthStatus" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="血型" prop="bloodType">
              <el-input v-if="isQueryMode" v-model="form.bloodType" :readonly="isReadOnly" />
              <el-select v-else v-model="form.bloodType" placeholder="请选择血型">
                <el-option label="A" value="A"></el-option>
                <el-option label="B" value="B"></el-option>
                <el-option label="AB" value="AB"></el-option>
                <el-option label="O" value="O"></el-option>
                <el-option label="未知" value="未知"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="入党年月日" prop="joinPartyDate">
              <el-date-picker clearable v-model="form.joinPartyDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择入党年月日" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="婚姻狀況" prop="marriageStatus">
              <el-input v-if="isQueryMode" v-model="form.marriageStatus" :readonly="isReadOnly" />
              <el-select v-else v-model="form.marriageStatus" placeholder="请选择婚姻状况">
                <el-option label="未婚" value="未婚"></el-option>
                <el-option label="已婚" value="已婚"></el-option>
                <el-option label="离婚" value="离婚"></el-option>
                <el-option label="丧偶" value="丧偶"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="结（离）婚日期" prop="marDirDate">
              <el-date-picker clearable v-model="form.marDirDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择结（离）婚日期" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="现工作单位" prop="currentEmployer">
              <el-input v-model="form.currentEmployer" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="原工作单位" prop="originalEmployer">
              <el-input v-model="form.originalEmployer" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="离职原因" prop="leaveReason">
              <el-input v-model="form.leaveReason" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="参加工作年月日" prop="employmentDate">
              <el-date-picker clearable v-model="form.employmentDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择参加工作年月日" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进入公司年月日" prop="enterWorkDate">
              <el-date-picker clearable v-model="form.enterWorkDate" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择进入公司年月日" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="进入三周年月日" prop="enterThreeworks">
              <el-date-picker clearable v-model="form.enterThreeworks" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择进入三周年月日" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="岗位性质" prop="jobNature">
              <el-input v-model="form.jobNature" placeholder="请输入岗位性质" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="人员类型" prop="personType">
              <el-input v-model="form.personType" placeholder="请输入人员类型" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="劳动关系" prop="laborRelation">
              <el-input v-model="form.laborRelation" placeholder="请输入劳动关系" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="专业技术职务" prop="professionTitle">
              <el-input v-model="form.profTitleTenure" placeholder="请输入专业技术职务（职称）" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="职务任职时间" prop="prof_title_tenure">
              <el-date-picker clearable v-model="form.profTitleTenure" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择专职务任职时间" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="现工作岗位" prop="currentPosition">
              <el-input v-model="form.currentPosition" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="现岗位任职时间" prop="currentTenure">
              <el-date-picker clearable v-model="form.currentTenure" type="date" value-format="yyyy-MM-dd"
                placeholder="请选择现岗位任职时间" :readonly="isReadOnly">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="家庭住址" prop="homeAddress">
              <el-input v-model="form.homeAddress" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="邮政编码" prop="postalCode">
              <el-input v-model="form.postalCode" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="家庭电话" prop="homeTelephone">
              <el-input v-model="form.homeTelephone" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="办公电话" prop="officeTelephone">
              <el-input v-model="form.officeTelephone" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="移动电话" prop="mobilePhone">
              <el-input v-model="form.mobilePhone" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="电子邮件" prop="email">
              <el-input v-model="form.email" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="户口性质" prop="householdNature">
              <el-input v-model="form.householdNature" placeholder="请输入户口性质" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="户口所在地" prop="householdRegistration">
              <el-input v-model="form.householdRegistration" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="出生地" prop="birthPlace">
              <el-input v-model="form.birthPlace" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="16">
            <el-form-item label="兴趣爱好" prop="hobby">
              <el-input v-model="form.hobby" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="懂何种外语" prop="knowForeign">
              <el-input v-model="form.knowForeign" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="外语证书名称" prop="foreignCertificate">
              <el-input v-model="form.foreignCertificate" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="熟练程度" prop="proficiency">
              <el-input v-if="isQueryMode" v-model="form.proficiency" :readonly="isReadOnly" />
              <el-select v-else v-model="form.proficiency" placeholder="请选择熟练程度">
                <el-option label="了解" value="了解"></el-option>
                <el-option label="熟悉" value="熟悉"></el-option>
                <el-option label="掌握" value="掌握"></el-option>
                <el-option label="熟练" value="熟练"></el-option>
                <el-option label="精通" value="精通"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="证书编码" prop="certificateCode">
              <el-input v-model="form.certificateCode" :readonly="isReadOnly" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPerson, getPerson, delPerson, addPerson, updatePerson } from "@/api/system/person";
import personAvatar from "./personAvatar";
export default {
  name: "Person",
  components: { personAvatar },
  dicts: ['sys_user_sex'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员基本信息表格数据
      personList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 添加这个状态来控制只读 
      isReadOnly: false,
      // 日期范围
      dateRange: [],
      // 岗位选项
      postOptions: [],
      // 初始化为true，表示处于编辑模式
      isQueryMode: true,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        userName: null,
        employeeId: null,
        rankId: null,
        sex: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        name: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        userName: [
          { required: true, message: "用户登录名不能为空", trigger: "blur" }
        ],
        identityCard: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
      },
      selectedNation: '', // 用于存储选中的56个民族  
      nationalitiesString: '汉族,蒙古族,回族,藏族,维吾尔族,苗族,彝族,壮族,布依族,朝鲜族,满族,侗族,瑶族,白族,土家族,哈尼族,哈萨克族,傣族,黎族,傈僳族,佤族,畲族,高山族,拉祜族,水族,东乡族,纳西族,景颇族,柯尔克孜族,土族,达斡尔族,仫佬族,羌族,布朗族,撒拉族,毛南族,仡佬族,锡伯族,阿昌族,普米族,塔吉克族,怒族,乌孜别克族,俄罗斯族,鄂温克族,德昂族,保安族,裕固族,京族,塔塔尔族,独龙族,鄂伦春族,赫哲族,门巴族,珞巴族,基诺族',
      nations: [], // 用于存储分割后的民族数组  
      selectPoliticsStatus: '', // 用于存储选中的13个政治面貌
      politicsStatuslitiesString: '中共党员,中共预备党员,共青团员,民革党员,民盟盟员,民建会员,民进会员,农工党党员,致公党党员,九三学社社员,台盟盟员,无党派人士,群众',
      politicsStatuses: [], //用于存储分割后的政治面貌数组
    };
  },
  created() {
    this.getList();
    getPerson().then(response => {
      this.postOptions = response.posts;
    }
    )
    // 在组件创建时，将字符串分割成数组  
    this.nations = this.nationalitiesString.split(',');
    this.politicsStatuses = this.politicsStatuslitiesString.split(',');
  },
  methods: {
    /** 查询人员基本信息列表 */
    getList() {
      this.loading = true;
      listPerson(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.personList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        personId: null,
        name: null,
        userName: null,
        headPhoto: null,
        employeeId: null,
        rankId: null,
        identityCard: null,
        formerName: null,
        sex: null,
        birthDate: null,
        nation: null,
        nativePlace: null,
        politicsStatus: null,
        healthStatus: null,
        bloodType: null,
        joinPartyDate: null,
        marriageStatus: null,
        marDirDate: null,
        currentEmployer: null,
        originalEmployer: null,
        leaveReason: null,
        employmentDate: null,
        enterWorkDate: null,
        enterThreeworks: null,
        jobNature: null,
        personType: null,
        laborRelation: null,
        professionTitle: null,
        profTitleTenure: null,
        currentPosition: null,
        currentTenure: null,
        homeAddress: null,
        postalCode: null,
        homeTelephone: null,
        officeTelephone: null,
        mobilePhone: null,
        email: null,
        householdNature: null,
        householdRegistration: null,
        birthPlace: null,
        hobby: null,
        knowForeign: null,
        foreignCertificate: null,
        proficiency: null,
        certificateCode: null,
        post: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.personId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      getPerson().then(response => {
        this.postOptions = response.posts;
        this.open = true;
        this.title = "添加人员信息";
        this.isReadOnly = false;
        this.isQueryMode = false;
      });
    },
    /** 详细按钮操作 */
    handleView(row) {
      this.reset();
      const personId = row.personId || this.ids
      getPerson(personId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看人员详细信息";
        this.isReadOnly = true; // 设置为只读
        this.isQueryMode = true; // 设置为只读
      });
      // this.open = true;
      // this.form = row;
      // this.isReadOnly = true; // 设置为只读
      // this.isQueryMode = true; // 设置为只读
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const personId = row.personId || this.ids
      getPerson(personId).then(response => {
        this.postOptions = response.posts;
        this.form = response.data;
        this.open = true;
        this.title = "修改人员基本信息";
        this.isReadOnly = false;
        this.isQueryMode = false;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.personId != null) {
            updatePerson(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPerson(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const personIds = row.personId || this.ids;
      this.$modal.confirm('是否确认删除人员基本信息编号为"' + personIds + '"的数据项？').then(function () {
        return delPerson(personIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/person/export', {
        ...this.queryParams
      }, `person_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
